<template>
	<view class="">
		<image src="/static/work1.jpg" mode="" class="img_bg" style="top: 0;"></image>
		<view class="">
			<view class="margin-r30 margin-l30">
				<block v-for="(item,index) in list" :key="index">
					<view class="card margin-t30 relative" @tap="toDetail(item.id,item.add_time,item.status)">
						<view :class="item.status=='1'?'jiaobiao':'jiaobiao2'">
							{{item.status==1?zhuangtai:yichang}}
						</view>
						
						<view class="text-36">{{item.danger_name?item.danger_name:"-"}}</view>
						<view class="display justify-between margin-t22">

							<view class="font-gray1">巡检时间</view>
							<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.add_time?item.add_time:"-"}}</view>
						</view>
						<view class="display justify-between margin-t22">
							<view class="font-gray1 ">巡检人</view>
							<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.userinfo.nickname?item.userinfo.nickname:"-"}}</view>
						</view>
						<view class="display justify-between margin-t22">
							<view class="font-gray1 ">所属部门</view>
							<view :class="item.danger_level==1?'font-0':item.danger_level==2?'font-1':item.danger_level==3?'font-2':item.danger_level==4?'font-3':''">{{item.userinfo.position_name?item.userinfo.position_name:"公司"}}</view>
						</view>
						<!-- 重新指派 -->
						<!-- <view class="" style="width: 150rpx;margin-left: 55%;color: #FFFFFF;background: #FF2400;position: absolute;top: 0;text-align: center;" @click.stop="reset(item)">
							点此重新指派
						</view> -->
					</view>
				</block>
				
				<view class="loading" v-show="!isShow">
					{{loadingText}}
				</view>
				<view class="text-center noNotice" v-show="isShow" style="margin-top: 200upx;">
					<image src="/static/notice.png" class="noticeImg"></image>
					<view class="font-gray margin-t30">暂无待指派任务~</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var page = 1,
		timer;
	export default {
		data() {
			return {
				uid: '',
				token: '',
				list: [],
				zhuangtai: '正常',
				yichang: '异常',
				loadingText: '上拉加载更多',
				isShow:false
			}
		},
		onLoad() {
			var _self = this
			this.uid = uni.getStorageSync('user').uid;
			this.token = uni.getStorageSync('user').token;
			this.getXunjian();
		},
		onPullDownRefresh: function() {
			this.getXunjian();
		},
		onReachBottom: function() {
			let that = this
			if (timer != null) {
				clearTimeout(timer)
			}
			timer = setTimeout(function() {
				that.getNewXunjian();
			}, 500);
		},
		methods: {
			//重新指派
			reset(item){
				console.log(item.is_reassign)
				if(item.is_reassign === 1){
					uni.request({
						url: 'https://aqmore.sxpz.vip/AppApi/Convenient/setReAssign?uid=' + this.uid + '&token=' + this.token +
							'&id=' + item.id,
						method: 'GET',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						success: function(res) {
							item.inspection_status=0
							console.log(res.data.datas.msg)
							uni.showToast({
								title:res.data.datas.msg
							})
						},
						fail() {
							uni.showToast({
								title:res.data.datas.msg
							})
						}
					})
				}else{
					uni.showToast({
						title:'您无法重新指派',
						icon:'none'
					})
				}
			},
			getXunjian() {
				page = 1;
				var _self = this
				uni.showNavigationBarLoading();
				this.loadingText = '上拉加载更多'
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/Convenient/getAssignList?uid=' + this.uid + '&token=' + this.token +
						'&p=' + page,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						console.log(res)
						if (res.data.code == 100) {
							console.log(res)
							uni.showToast({
								title: res.data.datas.msg,
								icon: 'none'
							})
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/index/index'
								})
								try {
									uni.removeStorageSync('user');
									console.log('chenggonmg')
								} catch (e) {
									// error
								}
							}, 1500)
						}
						if (res.data.code == 200) {
							if(res.data.datas.length==0){
								_self.isShow=true
							}
							_self.list = res.data.datas
							console.log(_self.list)
							uni.stopPullDownRefresh();
							uni.hideNavigationBarLoading();
							page++;
						}
					}
				})
			},
			getNewXunjian() {
				var _self = this
				if (this.loadingText == '已经加载全部巡检记录') {
					return false
				}
				this.loadingText = '加载中...'
				uni.showNavigationBarLoading();
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/Convenient/getAssignList?uid=' + this.uid + '&token=' + this.token +
						'&p=' + page,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						uni.hideNavigationBarLoading();
						if (res.data.datas.length == 0) {
							_self.loadingText = '已经加载全部巡检记录';
							return false
						}
						var newlist = res.data.datas
						_self.list = _self.list.concat(newlist)
						console.log(_self.list)
						page++;
					}
				})
			},
			toDetail(e, f, g) { //f为时间  g为状态 正常或异常
				uni.navigateTo({
					url: 'ZhipaiInformation?id=' + e + '&time=' + f + '&zhuangtai=' + g
				})
			}

		}
	}
</script>

<style>
	page {
		margin: 0;
		padding: 0;
		/* background-color: #0d98ed; */
	}

	.jiaobiao {
		position: absolute;
		height: 50upx;
		width: 80upx;
		right: 0;
		font-size: 100%;
		background-color: #00aa00;
		color: #FFFFFF;
		top: -3upx;
		border-radius: 10%;
		text-align: center;
	}

	.jiaobiao2 {
		position: absolute;
		height: 50upx;
		width: 80upx;
		right: 0;
		font-size: 100%;
		background-color: #ff0000;
		color: #FFFFFF;
		top: -3upx;
		border-radius: 10%;
		text-align: center;
	}

	.loading {
		line-height: 2em;
		text-align: center;
		color: #808080;
		margin-top: 30upx;
	}
</style>
